<template>
    <el-row class="tac">
        <el-col :span="24">
            <el-menu router style="height: 100%" class="aside" active-text-color="#409EFF">
                <div v-for="(item, index) in routes" :key="index">
                    <el-menu-item v-if="item.children === undefined" v-show="item.name" :index="item.path">
                        <span slot="title">{{ item.name }}</span>
                    </el-menu-item>

                    <el-submenu v-else :index="index + ''" v-show="item.name">
                        <template slot="title">
                            <span>{{ item.name }}</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item v-for="(child, indexj) in item.children" :key="indexj" :index="child.path">
                                {{ child.name }}
                            </el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                </div>
            </el-menu>
        </el-col>
    </el-row>
</template>

<script>

export default {
    name: 'tapNavigation',
    computed: {
        routes() {
            const {
                routes
            } = this.$router.options;
            let routerList = [];
            routes.forEach(item => {
                if (item.path === '/layout') {
                    const tempList = item.children.filter(routeItem => {
                        return routeItem.redirect === undefined;
                    });
                    routerList = tempList;
                }
            })
            const userInfo = JSON.parse(localStorage.getItem('userInfo'));


            if (userInfo.post !== 'teacher') {
                for (let i = 0; i < routerList.length; i++) {
                    const { children } = routerList[i];
                    const tempChildrenList = children?.filter(item => {
                        return item.name !== '论文审批';
                    })
                    routerList[i].children = tempChildrenList;
                }
            }


            if (userInfo.role !== 0) {
                const tempList = routerList.filter(item => {
                    return item.name !== '用户信息';
                })
                routerList = tempList;

                for (let i = 0; i < routerList.length; i++) {
                    const { children } = routerList[i];
                    const tempChildrenList = children?.filter(item => {
                        return item.name !== '论文查询';
                    })
                    routerList[i].children = tempChildrenList;
                }
            }
            return routerList;
        },
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        }
    }
}
</script>